package com.cliff.joinus;

import android.content.Context;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.androidquery.AQuery;

abstract public class JoinusMainBaseFragment extends ListFragment {

	protected View getItemView(View convertView, int iconResId, String name, String desc) {
		return getItemView(convertView, iconResId, name, desc, false);		
	}
	
	protected View getItemView(View convertView, int iconResId, String name, String desc, boolean selected) {
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) getActivity()
					.getApplicationContext().getSystemService(
							Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.item_line_name_desc,
					null);
		}
		
		AQuery aq = new AQuery(convertView);
		aq.id(R.id.lineicon).image(iconResId);
		aq.id(R.id.linename).text(name);
		
		if (selected) {
			TextView tv = aq.id(R.id.linedesc).getTextView();
			tv.setText("");
			tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.star_big_on, 0);		
		} else {
			TextView tv = aq.id(R.id.linedesc).getTextView();
			tv.setText(desc);
			tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);					
		}
		
		return convertView;		
	}
	
	abstract public void refresh();
	
}
